package com.chaodev.base.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.chaodev.base.dao.MemberDao;
import com.chaodev.base.model.Member;
import com.chaodev.base.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * vcbase
 *
 * @author 95634
 * @描述
 * @date 2023/5/22 11:12
 **/
@Service
public class MemberServiceImpl implements MemberService {

    @Autowired
    MemberDao memberDao;

    @Override
    public Member findDataById(String id) {
        return memberDao.findDataById(id);
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public void saveData(Member member) throws DataAccessException {
        if(ObjectUtil.isNotNull(member.getId())&&member.getId()>0){
            memberDao.updateDataById(member);
        }else{
            memberDao.insertData(member);
        }
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public void insertData(Member member) throws DataAccessException{
        memberDao.insertData(member);
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public void updateDataById(Member tbMember) throws DataAccessException{
        memberDao.updateDataById(tbMember);
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public void deleteDataById(String id) throws DataAccessException{
        memberDao.deleteDataById(id);
    }

    @Override
    public List<Member> queryDataList(Member tbMember) {
        return memberDao.queryDataList(tbMember);
    }

    @Override
    public PageInfo<Member> queryPageList(int start,int limit, Member tbMember) {
        PageHelper.startPage(start, limit);
        List<Member> tbMemberList = memberDao.queryDataList(tbMember);
        PageInfo<Member> pageInfo = new PageInfo<Member>(tbMemberList, limit);
        return pageInfo;
    }
}
